/// <reference path='./lib/node.d.ts'/>
/// <reference path='./lib/express.d.ts'/>
/// <reference path='./lib/nconf.d.ts'/>
/// <reference path='./lib/everyauth.d.ts'/>

/**
* MODULE DEPENDENCIES
* -------------------------------------------------------------------------------------------------
* include any modules you will use through out the file
**/

var express =  require("express");
var http =  require("http");
var nconf =  require("nconf");
var path =  require("path");


/**
* CONFIGURATION
* -------------------------------------------------------------------------------------------------
* load configuration settings from ENV, then settings.json.  Contains keys for OAuth logins. See 
* settings.example.json.  
**/
nconf.env().file({ file: 'settings.json' });

// add authentication 

var app = express();
app.configure(function() {
    app.set('port', process.env.PORT || 3000);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(express.cookieParser('azure zomg'));
    app.use(express.session());
    app.use(app.router);
    app.use(require('less-middleware')({ src: __dirname + '/public' }));
    app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function() {
    app.use(express.errorHandler());
});

/**
* ROUTING
* -------------------------------------------------------------------------------------------------
* include a route file for each major area of functionality in the site
**/
require('./routes/home')(app);
require('./routes/account')(app);

var server = http.createServer(app);

// to enable chatting....
var chat = require('./chat');


/**
* RUN
* -------------------------------------------------------------------------------------------------
* this starts up the server on the given port
**/

server.listen(process.env.PORT || 3000, process.env.HOST, function() {
    console.log("Server listening on " + (process.env.PORT || 3000));
});

